using System;
using System.Drawing;
using System.Collections;
using System.Xml.Serialization;

namespace MyViewer
{
    public enum eDisplayText
    {
        Nothing = 0,
        OnlyName,
        OnlyLevel,
        BothNameAndLevel,
        RaceAndClass,
        RaceAndClassAndLevel,
        Find
    }

    public class clsDisplayItem : ICloneable
    {
        [XmlAttribute("Visible")]
        public bool Visible = true;
        [XmlAttribute("DisplayText")]
        public eDisplayText DisplayText = eDisplayText.Nothing;
        [XmlAttribute("Name")]
        public string Name = "";
        [XmlAttribute("Color")]
        public int Color = System.Drawing.Color.White.ToArgb();

        public clsDisplayItem()
        {
        }

        public clsDisplayItem(bool visible, eDisplayText display, string name, int color)
        {
            Visible = visible;
            DisplayText = display;
            Name = name;
            Color = color;
        }

        public object Clone()
        {
            return new clsDisplayItem(Visible, DisplayText, Name, Color);
        }
    }

    [XmlRootAttribute("Settings", Namespace = "", IsNullable = false)]
    public class clsSettings
    {
        [XmlArray("DisplayItems")]
        [XmlArrayItem("DisplayItem", typeof(clsDisplayItem))]
        public ArrayList arrDisplayItems = new ArrayList();

        [XmlIgnore()]
        public Hashtable DisplayItems = new Hashtable();

        public void UpdateHashtable()
        {
            DisplayItems.Clear();
            foreach (clsDisplayItem di in arrDisplayItems)
            {
                try
                {
                    if (di.Name.StartsWith("[") && di.Name.EndsWith("]"))
                        DisplayItems.Add(di.Name, di);
                    else
                        DisplayItems.Add(di.Name.ToLower(), di);
                }
                catch
                {
                }
            }
        }

        public clsSettings()
        {
        }

        public void LoadDefaults()
        {
            arrDisplayItems.Clear();
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Metal Ore]", Color.White.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Weed]", Color.White.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Fish]", Color.White.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Treasure]", Color.Yellow.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Other]", Color.DarkTurquoise.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Object: Dynamic]", Color.YellowGreen.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Agressive]", Color.Red.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Neutral]", Color.Yellow.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Friendly]", Color.Green.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[NPC's: Dead]", Color.Gray.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.BothNameAndLevel, "[Players: Agressive]", Color.DarkRed.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Players: Neutral]", Color.Orange.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Players: Friendly]", Color.DarkGreen.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Players: Dead]", Color.Gray.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Player]", Color.White.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Target]", Color.Blue.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Party]", Color.DarkGreen.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Guild]", Color.DarkGreen.ToArgb()));
            arrDisplayItems.Add(new clsDisplayItem(true, eDisplayText.OnlyName, "[Find]", Color.DarkGreen.ToArgb()));
            UpdateHashtable();
        }

        public clsDisplayItem GetDisplayItem(string id, clsDisplayItem oldDI)
        {
            clsDisplayItem di = (clsDisplayItem)DisplayItems[id];
            if (di != null)
                return di;

            return oldDI;
        }

        [XmlAttribute("StayOnTop")]
        public bool StayOnTop = true;

        [XmlAttribute("FormX")]
        public int FormX = 0;
        [XmlAttribute("FormY")]
        public int FormY = 0;
        [XmlAttribute("FormWidth")]
        public int FormWidth = 300;
        [XmlAttribute("FormHeight")]
        public int FormHeight = 300;

        [XmlAttribute("RotateMap")]
        public bool RotateMap = false;
        [XmlAttribute("ShowMinimap")]
        public bool ShowMinimap = true;
        [XmlAttribute("MinimapRadius")]
        public int MinimapRadius = 1;
    }
}
